<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/actions/admin/AdminAction.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/actions/Response.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/model/Service/Service.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/utils/Logger.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/model/Service/ServiceFactory.php';
/**
 * Класс, отвечающий за редактирование структурного подразделения пользователем 
 * с ролью "администратор"
 */
final class DepartamentEditAction extends AdminAction {
	// см. родительский класс
	protected function execute(Response $response) {
		$serviceFactory = new ServiceFactory();
		$departmentService = $serviceFactory->getService('DepartamentService');
		$departmentIdentity = null;
		if(isset($_SESSION['department-identity'])) {
			$departmentIdentity = $_SESSION['department-identity'];
			unset($_SESSION['department-identity']);
		}
		if(isset($_POST['identity'])) {
			$departmentIdentity = $_POST['identity'];
		}
		if($departmentIdentity !== null) {
			$department = $departmentService->read($departmentIdentity);
			
			$response->setParameter('department', $department);
		}

		$departments = $departmentService->getAll();
		$response->setParameter('departments', $departments);

		$departmentTypeService = $serviceFactory->getService('DepartamentTypeService');
		$types = $departmentTypeService->getAll();
		$response->setParameter('types', $types);
		$personService = $serviceFactory->getService('PersonService');
		$persons = $personService->getAll();
		$response->setParameter('persons', $persons);
	}
}
?>